package com.example.myapplication.New;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.HotdetailsBean;
import com.example.myapplication.ShuJu.ManagementBean;
import com.google.gson.Gson;

import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Text;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class HotdetailsActivity extends AppCompatActivity {

    private  OkHttpClient okHttpClient;
    private  Gson gson ;
    private  Handler handler ;
    private String listID;
    private Request  request;
    private HotdetailsBean  hotdetailsBean;
    private WebView newText;
    private ImageView new_img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hotdetails);
        Intent intent = getIntent();
        listID = intent.getStringExtra("listID");
        initview();
        srndbean();
    }

    private void initview() {
        okHttpClient = new OkHttpClient();
        gson = new Gson();
        handler = new Handler();
        new_img = findViewById(R.id.new_img);
        newText = findViewById(R.id.newText);
    }
    private void srndbean() {
        request = new Request.Builder()
                .url("http://124.93.196.45:10001/prod-api/api/park/press/press/"+listID)
                .build();
        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(@NotNull Call call, @NotNull IOException e) {

            }

            @Override
            public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
                String string = response.body().string();
                hotdetailsBean = gson.fromJson(string,  HotdetailsBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        Glide.with(HotdetailsActivity.this).load("http://124.93.196.45:10001"+hotdetailsBean.getData().getCover()).into(new_img);
                        new_img.setScaleType(ImageView.ScaleType.FIT_XY);
                        newText.loadDataWithBaseURL(null,hotdetailsBean.getData().getContent(), "text/html", "UTF-8", null);
                    }
                });
            }
        });
    }
}